package com.sevennotes.classtable.data.class_items

import androidx.lifecycle.LiveData
import androidx.paging.PagingSource
import com.sevennotes.classtable.model.*
import kotlinx.coroutines.flow.Flow
import java.util.*

interface ClassesRespository {

    suspend fun getClassItems(tableId: Int): LiveData<List<ClassItemWithName>>

    suspend fun addClassItem(item: ClassItemWithName)

    suspend fun addClassItem(item: ClassItem)

    suspend fun deleteClassItem(itemId: Int)

    suspend fun updateClassItem(item: ClassItemWithName)

    suspend fun updateClassItem(item: ClassItem)

    suspend fun getAllStudents(): LiveData<List<StudentItem>>

    suspend fun addStudent(item: StudentInfo)

    suspend fun updateStudent(item: StudentInfo)

    suspend fun updateStudentGradePoint(studentItem: StudentItem)

    suspend fun deleteStudent(studentItem: StudentItem)

    suspend fun getStudentInfoById(studentId: Int, tableId: Int): StudentInfo?

    suspend fun addTableName(tableName: TableName): Long

    suspend fun deleteTableName(tableName: TableName)

    suspend fun updateTableName(tableName: TableName)

    suspend fun getAllTableNames(): LiveData<List<TableName>>

    suspend fun getTableCount(): Int

    suspend fun getFirstTableName(): TableName

    suspend fun copyClassesToNewTable(oldTableId: Int, newTableId: Int)

    suspend fun insertClassRecord(classRecord: ClassRecord)

    suspend fun insertClassAmountRecord(classAmountRecord: ClassAmountRecord)

    suspend fun insertGradePointRecord(gradePointRecord: GradePointRecord)

    suspend fun deleteClassAmountRecord(classAmountRecord: ClassAmountRecord)

    suspend fun deleteGradePointRecord(gradePointRecord: GradePointRecord)

    suspend fun getGpRecordById(studentId: Int): LiveData<List<GradePointRecord>>

    //清空添加的学生id为-1的临时内容
    suspend fun clearUnexistRecord()

    suspend fun getClassAmountRecordById(studentId: Int): LiveData<List<ClassAmountRecord>>

    fun getAllClassRecordOld(startTime: Date, toTime: Date, studentName: String): PagingSource<Int, ClassRecordWithName>
    fun getAllClassRecord(): PagingSource<Int, ClassRecordWithName>

    fun getClassRecordMonthStatistics(): Flow<List<ClassRecordMonthStatis>>

    fun getAllStartYears(): List<String>

    fun getClassRecordByYears(yearList: List<String>): List<ClassRecordWithName>

    suspend fun getClassRecordCount(startTime: Date, toTime: Date, studentName: String): Int

    suspend fun getAllClassRecordsByStudentId(studentId: Int): List<ClassRecord>

    suspend fun deleteClassRecord(classRecord: ClassRecord)

    suspend fun getBackupItem(): ClassTableBackup

    suspend fun clearAllDBs()

    suspend fun recovery(backup: ClassTableBackup)
}